//
//  bfxxTableViewController.m
//  tongxiangOASystem
//
//  Created by michael on 2018/5/17.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "bfxxTableViewController.h"
#import "bfxxTableViewCell.h"
@interface bfxxTableViewController ()
@property(strong,nonatomic)NSMutableArray * contentsArray;

@end

@implementation bfxxTableViewController
-(NSMutableArray*)contentsArray{
    if (_contentsArray == nil) {
        _contentsArray  = [NSMutableArray array];
    }
    return _contentsArray;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.contentsArray.count;
//return 1;
}
- (void)viewDidLoad {
    [super viewDidLoad];
        [self requestData];

    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)requestData{
if([self.type isEqualToString:@"zfxx"])
{_url =KexchangeRecord;
                _method = @"bfrylist";

}else if([self.type isEqualToString:@"zfxx"]){
    
                _method = @"tranrecordlist";

    } else if([self.type isEqualToString:@"qtxx"]){
    
                _method = @"qtlist";

    }
 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"unid":self.identifier},@{@"userId":userId}];
    __weak typeof(self) weakSelf = self;
    [HttpTools requestWithURL:KexchangeRecord arrays:array method:_method success:^(id JSON) {
   if ([JSON[@"data"] isKindOfClass: [NSArray class]]) {
            self.contentsArray = JSON[@"data"];
       

        }
         self.headview.frame = CGRectMake(0, 0, self.view.bounds.size.width, 40);
                self.tableView.tableHeaderView = self.headview;
                    [weakSelf.tableView reloadData];
         } failure:^(NSError *error) {
        
    }];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    bfxxTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bfxx" forIndexPath:indexPath];
    NSDictionary * dict = self.contentsArray[indexPath.row];
    
    
    cell.label1.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
            cell.label2.text =dict[@"name"];
    
    
    
    
    
    
    return cell;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
 
    // Configure the cell...
 
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
